import {Observable} from 'rxjs';
import {Injectable} from '@angular/core';
import {HttpService} from '../../../httpService';


@Injectable({
  providedIn: 'root'
})

export class SystemMgmtServices {
  private http: any;
  private Api_Urls: any;

  constructor(private Http: HttpService) {
    this.http = Http;
    this.Api_Urls = {
      // 数据字典 DD
      CREATE_DD: `http://${this.http.currentHost}:8080/system-management/data-dict`,
      DELETE_DD: `http://${this.http.currentHost}:8080/system-management/data-dict`,
      QUERY_DD: `http://${this.http.currentHost}:8080/system-management/data-dict/query`,
      EDIT_DD: `http://${this.http.currentHost}:8080/system-management/data-dict`,
      DELETE_DD_AND_ITEM: `http://${this.http.currentHost}:8080/system-management/data-dict/deletedictdtitem`,
      GET_ALL_DD_ITEM_BY_PARAM_TYPE: `http://${this.http.currentHost}:8080/system-management/data-dict-item/queryall`,

      QUERY_DD_ITEM: `http://${this.http.currentHost}:8080/system-management/data-dict-item/query`,
      EDIT_DD_ITEM: `http://${this.http.currentHost}:8080/system-management/data-dict-item`,
      DELETE_DD_ITEM: `http://${this.http.currentHost}:8080/system-management/data-dict-item`,
      CREATE_DD_ITEM: `http://${this.http.currentHost}:8080/system-management/data-dict-item`,

      // 系统参数 SysParams
      CREATE_SYS_PARAMS: `http://${this.http.currentHost}:8080/system-management/sys-param`,
      DELETE_SYS_PARAMS: `http://${this.http.currentHost}:8080/system-management/sys-param`,
      QUERY_SYS_PARAMS: `http://${this.http.currentHost}:8080/system-management/sys-param/query`,
      EDIT_SYS_PARAMS: `http://${this.http.currentHost}:8080/system-management/sys-param`,

      // 故障码 FaultCode
      CREATE_FAULT_CODE: `http://${this.http.currentHost}:8080/system-management/alarm-code`,
      DELETE_FAULT_CODE: `http://${this.http.currentHost}:8080/system-management/alarm-code`,
      QUERY_FAULT_CODE: `http://${this.http.currentHost}:8080/system-management/alarm-code/query`,
      EDIT_FAULT_CODE: `http://${this.http.currentHost}:8080/system-management/alarm-code`,

      // 协议点位 Protocol level
      CREATE_PROTOCOL_LEVEL: ``,
      DELETE_PROTOCOL_LEVEL: ``,
      QUERY_PROTOCOL_LEVEL: ``,
      EDIT_PROTOCOL_LEVEL: ``,

      // 线路 line
      CREATE_LINE: `http://${this.http.currentHost}:8080/system-management/line`,
      DELETE_LINE: `http://${this.http.currentHost}:8080/system-management/line`,
      QUERY_LINE: `http://${this.http.currentHost}:8080/system-management/line/query`,
      EDIT_LINE: `http://${this.http.currentHost}:8080/system-management/line`,
      GET_ALL_LINE: `http://${this.http.currentHost}:8080/system-management/line/queryall`,

      // 站点 Site
      CREATE_SITE: `http://${this.http.currentHost}:8080/system-management/site`,
      DELETE_SITE: `http://${this.http.currentHost}:8080/system-management/site`,
      QUERY_SITE: `http://${this.http.currentHost}:8080/system-management/site/query`,
      EDIT_SITE: `http://${this.http.currentHost}:8080/system-management/site`,
    };
  }

  public createDD({dictCode, dictDesc}): Observable<any> {
    return this.http.post(this.Api_Urls.CREATE_DD, {dictCode, dictDesc}, {});
  }

  public queryDD({start, size, keyword}): Observable<any> {
    return this.http.post(this.Api_Urls.QUERY_DD, {
      start,
      size,
      condition: {property: 'dictCode', operator: 'like', value: keyword}
    }, {});
  }

  public deleteDDAndItem(id): Observable<any> {
    return this.http.delete(this.Api_Urls.DELETE_DD_AND_ITEM + `/${id}`, {}, {});
  }

  public deleteDD(id): Observable<any> {
    return this.http.delete(this.Api_Urls.DELETE_DD + '/${id}', {}, {});
  }

  public editDD({dictCode, dictDesc, id}): Observable<any> {
    return this.http.put(this.Api_Urls.EDIT_DD + `/${id}`, {dictCode, dictDesc}, {});
  }

  public queryDDItem({start, size, dictId}): Observable<any> {
    return this.http.post(this.Api_Urls.QUERY_DD_ITEM, {
      start,
      size,
      condition: {property: 'dataDictId', operator: 'eq', value: dictId}
    }, {});
  }

  public createDDItem({itemName, itemValue, itemOrder, status, dictId}): Observable<any> {
    return this.http.post(this.Api_Urls.CREATE_DD_ITEM, {itemName, itemValue, itemOrder, status, dictId}, {});
  }

  public editDDItem({itemName, itemValue, itemOrder, status, dictId, id}): Observable<any> {
    return this.http.put(this.Api_Urls.EDIT_DD_ITEM + `/${id}`, {itemName, itemValue, itemOrder, status, dictId}, {});
  }

  public deleteDDItem(id): Observable<any> {
    return this.http.delete(this.Api_Urls.DELETE_DD_ITEM + `/${id}`, {}, {});
  }

  public querySystemParam({start, size, keyword}): Observable<any> {
    return this.http.post(this.Api_Urls.QUERY_SYS_PARAMS, {
      start,
      size,
      condition: {property: 'paramCode', operator: 'like', value: keyword}
    }, {});
  }

  public createSystemParam({paramCode, paramDesc, paramValue, paramType, isEncrypt}): Observable<any> {
    return this.http.post(this.Api_Urls.CREATE_SYS_PARAMS, {paramCode, paramDesc, paramValue, paramType, isEncrypt}, {});
  }

  public editSystemParam({paramCode, paramDesc, paramValue, paramType, isEncrypt, id}): Observable<any> {
    return this.http.put(this.Api_Urls.EDIT_SYS_PARAMS + `/${id}`, {paramCode, paramDesc, paramValue, paramType, isEncrypt}, {});
  }

  public deleteSystemParam(id): Observable<any> {
    return this.http.delete(this.Api_Urls.DELETE_SYS_PARAMS + `/${id}`, {}, {});
  }

  public queryFaultCode({start, size, keyword}): Observable<any> {
    return this.http.post(this.Api_Urls.QUERY_FAULT_CODE, {
      start,
      size,
      condition: {property: 'alarmCode', operator: 'like', value: keyword}
    }, {});
  }

  public createFaultCode({alarmCode, alarmModel, alarmDesc}): Observable<any> {
    return this.http.post(this.Api_Urls.CREATE_FAULT_CODE, {alarmCode, alarmModel, alarmDesc}, {});
  }

  public editFaultCode({alarmCode, alarmModel, alarmDesc, id}): Observable<any> {
    return this.http.put(this.Api_Urls.EDIT_FAULT_CODE + `/${id}`, {alarmCode, alarmModel, alarmDesc}, {});
  }

  public deleteFaultCode(id): Observable<any> {
    return this.http.delete(this.Api_Urls.DELETE_FAULT_CODE + `/${id}`, {}, {});
  }

  public getAllDataDictItem(): Observable<any> {
    return this.http.post(this.Api_Urls.GET_ALL_DD_ITEM_BY_PARAM_TYPE, {
      condition: {
        property: 'dataDictDictCode',
        operator: 'eq',
        value: 'param_type'
      }
    }, {});
  }

  public createLine({lineName, lineCity}): Observable<any> {
    return this.http.post(this.Api_Urls.CREATE_LINE, {lineName, lineCity}, {});
  }

  public queryLine({start, size, keyword}): Observable<any> {
    return this.http.post(this.Api_Urls.QUERY_LINE, {
      start,
      size,
      condition: {property: 'lineName', operator: 'like', value: keyword}
    }, {});
  }

  public editLine({lineName, lineCity, id}): Observable<any> {
    return this.http.put(this.Api_Urls.EDIT_LINE + `/${id}`, {lineName, lineCity}, {});
  }

  public deleteLine(id): Observable<any> {
    return this.http.delete(this.Api_Urls.DELETE_LINE + `/${id}`, {}, {});
  }

  public getAllLine(): Observable<any> {
    return this.http.post(this.Api_Urls.GET_ALL_LINE, {}, {});
  }

  public createSite({siteName, lineId, longitude, latitude}): Observable<any> {
    return this.http.post(this.Api_Urls.CREATE_SITE, {siteName, lineId, longitude, latitude}, {});
  }

  public querySite({start, size, keyword}): Observable<any> {
    return this.http.post(this.Api_Urls.QUERY_SITE, {
      start,
      size,
      condition: {property: 'siteName', operator: 'like', value: keyword}
    }, {});
  }

  public editSite({siteName, lineId, longitude, latitude, id}): Observable<any> {
    return this.http.put(this.Api_Urls.EDIT_SITE + `/${id}`, {siteName, lineId, longitude, latitude}, {});
  }

  public deleteSite(id): Observable<any> {
    return this.http.delete(this.Api_Urls.DELETE_SITE + `/${id}`, {}, {});
  }
}
